<?php

namespace App\Modules\Admin\Http\Requests;

use App\Http\Requests\Request;

class AdminCreateRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'email'     => 'required|unique:admins|email',
            'name'      => 'required',
            'mobile'     => 'required|numeric|regex:/^1[3456789][0-9]{9}$/|unique:admins',
            'username'  => 'required|min:4|max:14|unique:admins',
            'password'  => 'required|confirmed|min:6|max:14'
        ];
    }

    public function messages()
    {
        return  [
            'name.required' => '管理员姓名不能为空',
            'username.required' => '用户名不能为空',
            'username.unique' => '用户名已经存在',
            'mobile.required' => '手机号不能为空',
            'mobile.numeric|regex' => '手机号格式不正确',
            'mobile.unique' => '手机号已经存在',
            'email.unique' => '邮箱已经存在',
            'email.required' => '邮箱不能为空',
            'email.email' => '邮箱格式不正确',
            'password.required' => '密码不能为空',
            'password.confirmed' => '确认密码不正确',
            'password.min' => '密码不能小于6位',
            'password.max' => '密码不能大于14位',
        ];
    }
}
